<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<s:layout-render name="/layout.jsp" titlekey="hero.title">
    <s:layout-component name="body">
        <s:useActionBean beanclass="cz.muni.fi.pa165.dundd.web.HeroActionBean" var="actionBean"/>
        <h1 class="title" id="page-title"><f:message key="hero.title"/></h1>
        <div class="content">
            <div class="node node-page clearfix">   <h2><f:message key="hero.list.show"/></h2>
                <table class="basic">
                    <tr>
                        <th><h4>Id</h4></th>
                    <th><h4><f:message key="hero.list.name"/></h4></th>
                    <th><h4><f:message key="hero.list.xp"/></h4></th>
                    <th><h4><f:message key="hero.list.troop"/></h4></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    </tr>
                    <c:forEach items="${actionBean.heroes}" var="hero">
                        <tr>
                            <td><h6><c:out value="${hero.id}"/></h6></td>
                            <td><h6><c:out value="${hero.name}"/></h6></td>
                            <td><h6><c:out value="${hero.xp}"/></h6></td>
                            <td><h6><c:out value="${hero.myParty.name}"/></h6></td>

                            <sec:authorize ifAnyGranted="ROLE_ADMINISTRATOR">
                                <td>
                                    <s:form beanclass="cz.muni.fi.pa165.dundd.web.HeroActionBean">
                                        <s:param name="hero.id" value="${hero.id}"/>
                                        <s:submit name="edit" ><f:message key="hero.list.edit"/></s:submit>
                                    </s:form>
                                </td>
                                <td>
                                    <s:form beanclass="cz.muni.fi.pa165.dundd.web.HeroActionBean">
                                        <s:hidden name="hero.id" value="${hero.id}"/>
                                        <s:submit name="delete" ><f:message key="hero.list.delete"/></s:submit>
                                    </s:form>
                                </td>
                                <td>
                                    <s:form beanclass="cz.muni.fi.pa165.dundd.web.HeroActionBean">
                                        <s:hidden name="hero.id" value="${hero.id}"/>
                                        <s:submit name="editroles" ><f:message key="hero.list.roles"/></s:submit>
                                    </s:form>
                                </td>
                            </sec:authorize>

                            <c:set var="id"><sec:authentication property="principal.id" /></c:set>

                            <sec:authorize ifAnyGranted="ROLE_HERO">
                                <c:choose>
                                    <c:when test="${id == hero.id}">
                                        <td>
                                            <s:form beanclass="cz.muni.fi.pa165.dundd.web.HeroActionBean">
                                                <s:param name="hero.id" value="${hero.id}"/>
                                                <s:submit name="edit" ><f:message key="hero.list.edit"/></s:submit>
                                            </s:form>
                                        </td>
                                        <td>
                                            <s:form beanclass="cz.muni.fi.pa165.dundd.web.HeroActionBean">
                                                <s:hidden name="hero.id" value="${hero.id}"/>
                                                <s:submit name="delete" ><f:message key="hero.list.delete"/></s:submit>
                                            </s:form>
                                        </td>
                                        <td>
                                            <s:form beanclass="cz.muni.fi.pa165.dundd.web.HeroActionBean">
                                                <s:hidden name="hero.id" value="${hero.id}"/>
                                                <s:submit name="editroles" ><f:message key="hero.list.roles"/></s:submit>
                                            </s:form>
                                        </td>
                                    </c:when>
                                </c:choose>
                            </sec:authorize>

                        </tr>
                    </c:forEach>
                </table>
            </div>
        </div>
        <div class="content">
<!--            <div class="node node-page clearfix"> <h2><f:message key="hero.list.newhero"/></h2>
            <s:form beanclass="cz.muni.fi.pa165.dundd.web.HeroActionBean">                    
                <%@include file="form.jsp"%>
                <s:submit name="add"><f:message key="hero.list.create"/>
                </s:submit>
            </s:form>
        </div>-->
        </div>
    </s:layout-component>
</s:layout-render>